<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
    
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    利用vps搭建vpn |  jojoecfy的个人博客
  </title>
  <meta name="generator" content="hexo-theme-yilia-plus">
  
  <link rel="shortcut icon" href="/images/cfy.png" />
  
  
<link rel="stylesheet" href="/css/main.css">

  
<script src="/js/pace.min.js"></script>


  

  

</head>

</html>

<body>
  <div id="app">
    <main class="content">
      <section class="outer">
  <article id="post-v2ray" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  利用vps搭建vpn
</h1>
  

    </header>
    

    
    <div class="article-meta">
      <a href="/2020/03/21/v2ray/" class="article-date">
  <time datetime="2020-03-21T10:44:56.000Z" itemprop="datePublished">2020-03-21</time>
</a>
      
      
      
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">1.5k字</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">5分钟</span>
        </span>
    </span>
</div>

      
    </div>
    

    
    
    <div class="tocbot"></div>





    

    
    <div class="article-entry" itemprop="articleBody">
      


      

      
      <h2 id="概述"><a href="#概述" class="headerlink" title="概述"></a>概述</h2><p>许多小伙伴在google或者外国网站查阅资料时，网速很慢或者经常无法访问，今天笔者就带各位搭建自己的vpn。内容包括VPS购买，连接VPS，一键搭建V2ray和SS，开启bbr加速，客户端配置</p>
<a id="more"></a>  

<h2 id="一、基本概念"><a href="#一、基本概念" class="headerlink" title="一、基本概念"></a>一、基本概念</h2><h3 id="1-什么是墙"><a href="#1-什么是墙" class="headerlink" title="1.什么是墙"></a>1.什么是墙</h3><pre><code>GFW：防火长城（英文名称Great Firewall of China，简写为Great Firewall，缩写GFW），也称中国防火墙或中国国家防火墙
，指中华人民共和国政府在其管辖因特网内  部建立的多套网络审查系统的总称，包括相关行政审查系统。GFW中的主要技术包括
国家入口网关的IP封锁、主干路由器的关键字过滤阻断、域名劫持和HTTPS证书过滤等4种。那些被限制的网站，根本原因是因为
其网站上发布了中国政府不能接受的政治等方面的内容，有些综合性或技术性的网站只是含有少量的或可能牵涉到这些信息也会
被整体封锁，例如曾经对于Google、维基百科的全面封锁，还有就是对色情、青少年犯罪等网站的禁止。
这是百度出来的结果，通俗来讲，gfw就是用来阻止中国大陆网民访问一些国外网站的防火墙，而其中有些网站我们总要用到
比如github，Google等，而我们将要搭建的v2ray就可以很好的解决这个问题。</code></pre><h3 id="2-基本原理"><a href="#2-基本原理" class="headerlink" title="2. 基本原理"></a>2. 基本原理</h3><pre><code>gfw封锁网站主要分两种方式，一种是依靠人工举报，另一种是机器检测，人工检测暂且不谈，机器检测主要策略包括关键字检测、
ip封锁、特定端口封锁、dns污染等形式。
而我们采用的形式是购买一台不被墙的境外服务器，利用其搭建我们的环境，从而避开墙的干扰。</code></pre><h2 id="二、搭建过程"><a href="#二、搭建过程" class="headerlink" title="二、搭建过程"></a>二、搭建过程</h2><h3 id="1、购买vps"><a href="#1、购买vps" class="headerlink" title="1、购买vps"></a>1、购买vps</h3><pre><code>市面上可供我们选择的vps有很多种，包括搬瓦工、谷歌云、vultr等，谷歌云的优势就是便宜（基本免费）
但需要国外信用卡，搬瓦工稳定，但是价格略贵，出于经济和性能的考虑，
我选择了vultr，付款方便，并且不使用也不会收费。
在vultr的官网上注册完毕后，我们就可以选择我们要搭建vps的配置了，我选
择的是最便宜的云计算服务器，一个月5美元，
之后我们可以选择服务器位置和操作系统， 之后我们点击deploy now 我们的vps就搭建完了。</code></pre><img src="https://raw.githubusercontent.com/jojoecfy/pic/master/20200415204507.png"/>

<p>我们可以看到我们服务器的ip，这里我们要利用ping工具检测此ip是否被墙 ，如果被墙就重复以上步骤直到建立起一个不被墙的vps<br>   <img src="https://raw.githubusercontent.com/jojoecfy/pic/master/20200415203439.png"/><br>   <img src="https://raw.githubusercontent.com/jojoecfy/pic/master/ping.png"/></p>
<h3 id="2、安装环境"><a href="#2、安装环境" class="headerlink" title="2、安装环境"></a>2、安装环境</h3><p>   之后我们需要安装Xshell操纵我们的服务器。<br>    利用xshell连接至我们的服务器，首先，我们要关闭服务器防火墙</p>
<pre><code>其次同步服务器时间</code></pre><blockquote>
<p>ln -sf /usr/share/zoneinfo/Asia/Shanghai  /etc/localtime</p>
</blockquote>
<p>下载并启动 v2ray 脚本 </p>
<blockquote>
<p> wget <a href="https://install.direct/go.sh" target="_blank" rel="noopener">https://install.direct/go.sh</a><br>bash go.sh<br>systemctl start v2ray </p>
</blockquote>
<pre><code>此时查看进程，会发现v2ray进程已经启动</code></pre><h3 id="3、客户端下载"><a href="#3、客户端下载" class="headerlink" title="3、客户端下载"></a>3、客户端下载</h3><pre><code>接下来我们要下载客户端
链接：https://pan.baidu.com/s/1DsUUod6W8oxyexNSrzbA7w  提取码：7bjt
这是Windows和安卓的客户端。
下载完后打开客户端
填写内容</code></pre><img src="https://raw.githubusercontent.com/jojoecfy/pic/master/v2ray-1.png"/>


<pre><code>用户id 额外id，在v2ray。conf里</code></pre><img src="https://raw.githubusercontent.com/jojoecfy/pic/master/v2ray-3.png"/>


<pre><code>客户端设置 路由规则</code></pre><img src="https://raw.githubusercontent.com/jojoecfy/pic/master/v2ray-2.png"/>


<pre><code>开启pac 代理 
此时你就可以连上google YouTube的网站了</code></pre><h3 id="4、bbr加速"><a href="#4、bbr加速" class="headerlink" title="4、bbr加速"></a>4、bbr加速</h3><pre><code>网速其实并不理想，
此时我们需要开启bbr加速</code></pre><blockquote>
<p>wget –no-check-certificate <a href="https://github.com/teddysun/across/raw/master/bbr.sh" target="_blank" rel="noopener">https://github.com/teddysun/across/raw/master/bbr.sh</a> &amp;&amp; chmod +x bbr.sh &amp;&amp; ./bbr.sh<br>   开启bbr 需要确认内核版本》=4.2<br>uname -r<br>   始终无法提升内核版本可按以下命令操作</p>
</blockquote>
<blockquote>
<p>rpm –import <a href="https://www.elrepo.org/RPM-GPG-KEY-elrepo.org" target="_blank" rel="noopener">https://www.elrepo.org/RPM-GPG-KEY-elrepo.org</a><br>yum install <a href="https://www.elrepo.org/elrepo-release-7.0-3.el7elrepo.noarch.rpm" target="_blank" rel="noopener">https://www.elrepo.org/elrepo-release-7.0-3.el7elrepo.noarch.rpm</a><br>yum –disablerepo=”*” –enablerepo=”elrepo-kernel” listavailable<br>vi /etc/default/grub<br>GRUB_DEFAULT=0<br>grub2-mkconfig -o /boot/grub2/grub.cfg<br>之后重启服务器，确认内核版本</p>
</blockquote>
<p>输入</p>
<blockquote>
<p>sysctl net.ipv4.tcp_congestion_control<br>输出 net.ipv4.tcp_congestion_control = bbr 即为成功</p>
</blockquote>
<img src="https://raw.githubusercontent.com/jojoecfy/pic/master/youtube.png"/>

<h2 id="三、注意事项"><a href="#三、注意事项" class="headerlink" title="三、注意事项"></a>三、注意事项</h2><pre><code>1、时间同步
    时间一定要与我们的时间同步，否则会连接不上
2、开启服务
    如遇到问题，多多查看进程，确认服务处于开启状态
3、防火墙
    除了关闭防火墙还须确认selinux 状态，这两个都要关，避免出现不必要麻烦</code></pre><h2 id="四、搭建nextcloud"><a href="#四、搭建nextcloud" class="headerlink" title="四、搭建nextcloud"></a>四、搭建nextcloud</h2><pre><code>既然服务器买完了，闲着也是闲着，不如用来搭一个云盘。我们利用nextcloud搭建我们的云盘。</code></pre><h3 id="1、-环境搭建"><a href="#1、-环境搭建" class="headerlink" title="1、 环境搭建"></a>1、 环境搭建</h3><pre><code>nextcloud可以依赖nginx 和Apache运行，在本文中我们利用Apache服务，除此之外，我们需要安装php7.2，mysql环境
按以下命令安装并启动服务即可</code></pre><blockquote>
<p>yum install httpd<br>systemctl start httpd<br>systemctl enable httpd</p>
</blockquote>
<blockquote>
<p>rpm -Uvh <a href="https://mirror.webtatic.com/yum/el7/epel-release.rpm" target="_blank" rel="noopener">https://mirror.webtatic.com/yum/el7/epel-release.rpm</a><br>rpm -Uvh <a href="https://mirror.webtatic.com/yum/el7/webtatic-release.rpm" target="_blank" rel="noopener">https://mirror.webtatic.com/yum/el7/webtatic-release.rpm</a><br>yum install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache  &gt; php72w-pdo php72w-xml php72w-ldap php72w-mcrypt<br>service php-fpm start<br>systemctl enable php-fpm</p>
</blockquote>
<blockquote>
<p>yum install mariadb-server.x86_64<br>systemctl start mariadb<br>mysqladmin -u root password ‘123456’<br>mysql -u root -p123456<br>创建数据库：MariaDB [(none)]&gt; create database nextcloud;</p>
<p>GRANT ALL PRIVILEGES ON <em>.</em> TO ‘root’@’%’ IDENTIFIED BY ‘123456’ WITH GRANT OPTION;<br>flush privileges；</p>
</blockquote>
<h3 id="2、-下载nextcloud"><a href="#2、-下载nextcloud" class="headerlink" title="2、 下载nextcloud"></a>2、 下载nextcloud</h3><pre><code>在安装完毕后，我们需要下载nextcloud，有两种方式，一是下载nextcloudzip包，二是下载安装脚本
在本文中我们着重讲第二种方式
在/www/var/html下新建文件夹 nextcloud
我们需要下载setupnextcloud.php脚本至新建目录下，访问ip/nextcloud/setupnextcloud.php
wget https://download.nextcloud.com/server/installer/setup-nextcloud.php
按网页所提示步骤进行
如果有错误信息，要根据提示解决错误重新访问</code></pre><img src="https://raw.githubusercontent.com/jojoecfy/pic/master/nextcloud-1.png"/>

<img src="https://raw.githubusercontent.com/jojoecfy/pic/master/nextcloud-2.png"/>

<img src="https://raw.githubusercontent.com/jojoecfy/pic/master/nextcloud-3.png"/>

<img src="https://raw.githubusercontent.com/jojoecfy/pic/master/nextcloud-4.png"/>
      
      <!-- reward -->
      
    </div>
    
    
      <!-- copyright -->
      
        <div class="declare">
          <ul class="post-copyright">
            <li>
              <i class="ri-copyright-line"></i>
              <strong>版权声明： </strong s>
              本博客所有文章除特别声明外，均采用 <a href="https://www.apache.org/licenses/LICENSE-2.0.html" rel="external nofollow"
                target="_blank">Apache License 2.0</a> 许可协议。转载请注明出处！
            </li>
          </ul>
        </div>
        
    <footer class="article-footer">
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/linux/" rel="tag">linux</a></li></ul>


    </footer>

  </div>

  
  
  <nav class="article-nav">
    
    
      <a href="/2020/03/01/stream/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">stream流简单应用</div>
      </a>
    
  </nav>


  

  
  
<!-- valine评论 -->
<div id="vcomments-box">
    <div id="vcomments">
    </div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src='https://cdn.jsdelivr.net/npm/valine@1.3.10/dist/Valine.min.js'></script>
<script>
    new Valine({
        el: '#vcomments',
        app_id: 'hVXA4YKowVsvPVBi9VpCSsFP-gzGzoHsz',
        app_key: 'TowHJn0OK2oMVqgOPiONsbaT',
        path: window.location.pathname,
        notify: 'false',
        verify: 'false',
        avatar: 'identicon',
        placeholder: '给我的文章加点评论吧~',
        recordIP: true
    });
    const infoEle = document.querySelector('#vcomments .info');
    if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
        infoEle.childNodes.forEach(function (item) {
            item.parentNode.removeChild(item);
        });
    }
</script>
<style>
    #vcomments-box {
        padding: 5px 30px;
    }

    @media screen and (max-width: 800px) {
        #vcomments-box {
            padding: 5px 0px;
        }
    }

    #vcomments-box #vcomments {
        background-color: #fff;
    }

    .v .vlist .vcard .vh {
        padding-right: 20px;
    }

    .v .vlist .vcard {
        padding-left: 10px;
    }
</style>

  

  
  
  

</article>
</section>
      <footer class="footer">
  <div class="outer">
    <ul class="list-inline">
      <li>
        &copy;
        2020
        jojoecfy
      </li>
      <li>
        
      </li>
    </ul>
    <ul class="list-inline">
      <li>
        
        
        <span>
  <i>PV:<span id="busuanzi_value_page_pv"></span></i>
  <i>UV:<span id="busuanzi_value_site_uv"></span></i>
</span>
        
      </li>
      
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278657708&amp;web_id=1278657708'></script>
        
      </li>
    </ul>
  </div>
</footer>
      <div class="to_top">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>
      </div>
    </main>
    <aside class="sidebar">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/cfy.png" alt="jojoecfy的个人博客"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="Search">
        <i class="ri-search-line"></i>
      </a>
      
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    
  </div>
</div>
    
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/jquery.justifiedGallery.min.js"></script>


<script src="/js/lazyload.min.js"></script>


<script src="/js/busuanzi-2.3.pure.min.js"></script>


<script src="/js/share.js"></script>



<script src="/fancybox/jquery.fancybox.min.js"></script>







<script src="/js/tocbot.min.js"></script>

<script>
  // Tocbot_v4.7.0  http://tscanlin.github.io/tocbot/
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer:'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto',
    onClick: (e) => {
      $('.toc-link').removeClass('is-active-link');
      $(`a[href=${e.target.hash}]`).addClass('is-active-link');
      $(e.target.hash).scrollIntoView();
      return false;
    }
  });
</script>


<script>
  var ayerConfig = {
    mathjax: false
  }
</script>


<script src="/js/ayer.js"></script>


<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">


<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>




<script type="text/javascript" src="https://js.users.51.la/20544303.js"></script>

    
  </div>
</body>

</html>